package com.warm.pump.module.work.dao.gen;

import java.util.List;
import java.util.Map;
import java.util.Date;
import java.math.BigDecimal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.TypeCast;
import com.warm.pump.frame.gen.exception.ServiceException;
import com.warm.pump.module.work.bean.po.gen.WorkSubject;
import com.warm.pump.module.work.mapper.gen.WorkSubjectMapper;
import com.warm.pump.module.work.bean.po.gen.WorkSubjectExample;

@Repository
public class WorkSubjectDao {
    // 日志对象
    private transient Log log = LogFactory.getLog(this.getClass());
    @Autowired
    private WorkSubjectMapper workSubjectMapper;

    // 增加一个后台WorkSubject表

    public boolean insert(WorkSubject workSubject) {
        try {
            workSubjectMapper.insert(workSubject);
            log.debug("后台WorkSubject表增加成功");
            return true;
        } catch (Exception e) {
            log.debug("后台WorkSubject表增加失败");
            throw new ServiceException("后台WorkSubject表增加失败", e);
        }
    }
    // 增加一个后台WorkSubject表Selective

    public boolean insertSelective(WorkSubject workSubject) {
        try {
            workSubjectMapper.insertSelective(workSubject);
            log.debug("后台WorkSubject表增加成功");
            return true;
        } catch (Exception e) {
            log.debug("后台WorkSubject表增加失败");
            throw new ServiceException("后台WorkSubject表增加失败", e);
        }
    }

    // 删除一个后台WorkSubject表

    public boolean deleteByPrimaryKey(Long id) {
        try {
            workSubjectMapper.deleteByPrimaryKey(id);
            log.debug("后台WorkSubject表删除成功");
            return true;
        } catch (Exception e) {
            log.debug("后台WorkSubject表删除失败");
            throw new ServiceException("后台WorkSubject表删除失败", e);
        }
    }
    // 删除一个后台WorkSubject表byMap

    public boolean deleteByMap(Map workSubjectMap) {
        try {
            workSubjectMapper.deleteByExample(createWorkSubjectExample(workSubjectMap, null, null));
            log.debug("后台WorkSubject根据Map删除成功");
            return true;
        } catch (Exception e) {
            log.debug("后台WorkSubject根据GroupID删除失败");
            throw new ServiceException("后台WorkSubject根据object删除失败", e);
        }
    }
    // 修改一个后台WorkSubject表

    public boolean updateByPrimaryKey(WorkSubject workSubject) {
        try {
            workSubjectMapper.updateByPrimaryKey(workSubject);
            log.debug("后台WorkSubject表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台WorkSubject表修改失败");
            throw new ServiceException("后台WorkSubject表修改失败", e);
        }
    }
    // 修改一个后台WorkSubject表Selective

    public boolean updateByPrimaryKeySelective(WorkSubject workSubject) {
        try {
            workSubjectMapper.updateByPrimaryKeySelective(workSubject);
            log.debug("后台WorkSubject表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台WorkSubject表修改失败");
            throw new ServiceException("后台WorkSubject表修改失败", e);
        }
    }
    // 修改一个后台WorkSubject表

    public boolean updateByMap(WorkSubject workSubject, Map workSubjectMap) {
        try {
            workSubjectMapper.updateByExample(workSubject, createWorkSubjectExample(workSubjectMap, null, null));
            log.debug("后台批量WorkSubject表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台批量WorkSubject表修改失败");
            throw new ServiceException("后台WorkSubject表批量修改失败", e);
        }
    }
    // 修改一个后台WorkSubject表Selective

    public boolean updateByMapSelective(WorkSubject workSubject, Map workSubjectMap) {
        try {
            workSubjectMapper.updateByExampleSelective(workSubject, createWorkSubjectExample(workSubjectMap, null, null));
            log.debug("后台批量WorkSubject表修改成功");
            return true;
        } catch (Exception e) {
            log.debug("后台批量WorkSubject表修改失败");
            throw new ServiceException("后台WorkSubject表批量修改失败", e);
        }
    }

    // 查询一个后台WorkSubject表

    public WorkSubject selectByPrimaryKey(Long id) {
        return workSubjectMapper.selectByPrimaryKey(id);
    }

    // 查询一个后台WorkSubject表-根据map

    public WorkSubject selectByMap(Map workSubjectMap) {
        List<WorkSubject> list = getListByMap(workSubjectMap);
        if (list == null || list.isEmpty()) {
            return null;
        } else {
            return list.get(0);
        }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 查询所有后台WorkSubject表

    public List<WorkSubject> getListByMap(Map workSubjectMap) {

        return workSubjectMapper.selectByExample(createWorkSubjectExample(workSubjectMap, null, null));
    }

    //统计后台WorkSubject表数量

    public int countTotalByMap(Map workSubjectMap) {

        return workSubjectMapper.countByExample(createWorkSubjectExample(workSubjectMap, null, null));
    }


    public List<WorkSubject> getListByMapPage(Map workSubjectMap, int limitStart,
                                              int limitOffset) {

        return workSubjectMapper.selectByExample(createWorkSubjectExample(workSubjectMap, limitStart, limitOffset));
    }


    public PageBean getPageBeanByMap(Map workSubjectMap, int pageNo, int pageSize) {
        Integer count = countTotalByMap(workSubjectMap);
        PageBean pageBean = new PageBean();
        pageBean.setCount(count);
        pageBean.setPageNo(pageNo);
        pageBean.setPageSize(pageSize);
        int limitStart = pageBean.getStartNo();
        int limitOffset = pageSize;
        pageBean.setData(workSubjectMapper.selectByExample(createWorkSubjectExample(workSubjectMap, limitStart, limitOffset)));
        return pageBean;
    }

    private WorkSubjectExample createWorkSubjectExample(Map workSubjectMap, Integer limitStart, Integer limitOffset) {
        WorkSubjectExample workSubjectEx = new WorkSubjectExample();
        WorkSubjectExample.Criteria c = workSubjectEx.createCriteria();
        Long id_null = TypeCast.getLong(workSubjectMap.get("id_null"));
        Long id_notNull = TypeCast.getLong(workSubjectMap.get("id_notNull"));
        Long id = TypeCast.getLong(workSubjectMap.get("id"));
        Long id_not = TypeCast.getLong(workSubjectMap.get("id_not"));
        Long id_greater = TypeCast.getLong(workSubjectMap.get("id_greater"));
        Long id_greaterEqual = TypeCast.getLong(workSubjectMap.get("id_greaterEqual"));
        Long id_less = TypeCast.getLong(workSubjectMap.get("id_less"));
        Long id_lessEqual = TypeCast.getLong(workSubjectMap.get("id_lessEqual"));
        List<Long> id_in = TypeCast.getLongList(workSubjectMap.get("id_in"));
        List<Long> id_notIn = TypeCast.getLongList(workSubjectMap.get("id_notIn"));
        Long id_between1 = TypeCast.getLong(workSubjectMap.get("id_between1"));
        Long id_between2 = TypeCast.getLong(workSubjectMap.get("id_between2"));
        Long id_notBetween1 = TypeCast.getLong(workSubjectMap.get("id_notBetween1"));
        Long id_notBetween2 = TypeCast.getLong(workSubjectMap.get("id_notBetween2"));

        if (id_null != null) {
            c.andIdIsNull();
        }
        if (id_notNull != null) {
            c.andIdIsNotNull();
        }
        if (id != null) {
            c.andIdEqualTo(id);
        }
        if (id_not != null) {
            c.andIdNotEqualTo(id_not);
        }
        if (id_greater != null) {
            c.andIdGreaterThan(id_greater);
        }
        if (id_greaterEqual != null) {
            c.andIdGreaterThanOrEqualTo(id_greaterEqual);
        }
        if (id_less != null) {
            c.andIdLessThan(id_less);
        }
        if (id_lessEqual != null) {
            c.andIdLessThanOrEqualTo(id_lessEqual);
        }
        if (id_in != null) {
            c.andIdIn(id_in);
        }
        if (id_notIn != null) {
            c.andIdNotIn(id_notIn);
        }
        if (id_between1 != null) {
            c.andIdBetween(id_between1, id_between2);
        }
        if (id_notBetween1 != null) {
            c.andIdNotBetween(id_notBetween1, id_notBetween2);
        }
        String subjectName_null = TypeCast.getString(workSubjectMap.get("subjectName_null"));
        String subjectName_notNull = TypeCast.getString(workSubjectMap.get("subjectName_notNull"));
        String subjectName = TypeCast.getString(workSubjectMap.get("subjectName"));
        String subjectName_not = TypeCast.getString(workSubjectMap.get("subjectName_not"));
        String subjectName_greater = TypeCast.getString(workSubjectMap.get("subjectName_greater"));
        String subjectName_greaterEqual = TypeCast.getString(workSubjectMap.get("subjectName_greaterEqual"));
        String subjectName_less = TypeCast.getString(workSubjectMap.get("subjectName_less"));
        String subjectName_lessEqual = TypeCast.getString(workSubjectMap.get("subjectName_lessEqual"));
        String subjectName_like = TypeCast.getString(workSubjectMap.get("subjectName_like"));
        String subjectName_notLike = TypeCast.getString(workSubjectMap.get("subjectName_notLike"));
        List<String> subjectName_in = TypeCast.getStringList(workSubjectMap.get("subjectName_in"));
        List<String> subjectName_notIn = TypeCast.getStringList(workSubjectMap.get("subjectName_notIn"));
        String subjectName_between1 = TypeCast.getString(workSubjectMap.get("subjectName_between1"));
        String subjectName_between2 = TypeCast.getString(workSubjectMap.get("subjectName_between2"));
        String subjectName_notBetween1 = TypeCast.getString(workSubjectMap.get("subjectName_notBetween1"));
        String subjectName_notBetween2 = TypeCast.getString(workSubjectMap.get("subjectName_notBetween2"));

        if (subjectName_null != null) {
            c.andSubjectNameIsNull();
        }
        if (subjectName_notNull != null) {
            c.andSubjectNameIsNotNull();
        }
        if (subjectName != null) {
            c.andSubjectNameEqualTo(subjectName);
        }
        if (subjectName_not != null) {
            c.andSubjectNameNotEqualTo(subjectName_not);
        }
        if (subjectName_greater != null) {
            c.andSubjectNameGreaterThan(subjectName_greater);
        }
        if (subjectName_greaterEqual != null) {
            c.andSubjectNameGreaterThanOrEqualTo(subjectName_greaterEqual);
        }
        if (subjectName_less != null) {
            c.andSubjectNameLessThan(subjectName_less);
        }
        if (subjectName_lessEqual != null) {
            c.andSubjectNameLessThanOrEqualTo(subjectName_lessEqual);
        }
        if (subjectName_like != null) {
            c.andSubjectNameLike(subjectName_like);
        }
        if (subjectName_notLike != null) {
            c.andSubjectNameNotLike(subjectName_notLike);
        }
        if (subjectName_in != null) {
            c.andSubjectNameIn(subjectName_in);
        }
        if (subjectName_notIn != null) {
            c.andSubjectNameNotIn(subjectName_notIn);
        }
        if (subjectName_between1 != null) {
            c.andSubjectNameBetween(subjectName_between1, subjectName_between2);
        }
        if (subjectName_notBetween1 != null) {
            c.andSubjectNameNotBetween(subjectName_notBetween1, subjectName_notBetween2);
        }
        String remark_null = TypeCast.getString(workSubjectMap.get("remark_null"));
        String remark_notNull = TypeCast.getString(workSubjectMap.get("remark_notNull"));
        String remark = TypeCast.getString(workSubjectMap.get("remark"));
        String remark_not = TypeCast.getString(workSubjectMap.get("remark_not"));
        String remark_greater = TypeCast.getString(workSubjectMap.get("remark_greater"));
        String remark_greaterEqual = TypeCast.getString(workSubjectMap.get("remark_greaterEqual"));
        String remark_less = TypeCast.getString(workSubjectMap.get("remark_less"));
        String remark_lessEqual = TypeCast.getString(workSubjectMap.get("remark_lessEqual"));
        String remark_like = TypeCast.getString(workSubjectMap.get("remark_like"));
        String remark_notLike = TypeCast.getString(workSubjectMap.get("remark_notLike"));
        List<String> remark_in = TypeCast.getStringList(workSubjectMap.get("remark_in"));
        List<String> remark_notIn = TypeCast.getStringList(workSubjectMap.get("remark_notIn"));
        String remark_between1 = TypeCast.getString(workSubjectMap.get("remark_between1"));
        String remark_between2 = TypeCast.getString(workSubjectMap.get("remark_between2"));
        String remark_notBetween1 = TypeCast.getString(workSubjectMap.get("remark_notBetween1"));
        String remark_notBetween2 = TypeCast.getString(workSubjectMap.get("remark_notBetween2"));

        if (remark_null != null) {
            c.andRemarkIsNull();
        }
        if (remark_notNull != null) {
            c.andRemarkIsNotNull();
        }
        if (remark != null) {
            c.andRemarkEqualTo(remark);
        }
        if (remark_not != null) {
            c.andRemarkNotEqualTo(remark_not);
        }
        if (remark_greater != null) {
            c.andRemarkGreaterThan(remark_greater);
        }
        if (remark_greaterEqual != null) {
            c.andRemarkGreaterThanOrEqualTo(remark_greaterEqual);
        }
        if (remark_less != null) {
            c.andRemarkLessThan(remark_less);
        }
        if (remark_lessEqual != null) {
            c.andRemarkLessThanOrEqualTo(remark_lessEqual);
        }
        if (remark_like != null) {
            c.andRemarkLike(remark_like);
        }
        if (remark_notLike != null) {
            c.andRemarkNotLike(remark_notLike);
        }
        if (remark_in != null) {
            c.andRemarkIn(remark_in);
        }
        if (remark_notIn != null) {
            c.andRemarkNotIn(remark_notIn);
        }
        if (remark_between1 != null) {
            c.andRemarkBetween(remark_between1, remark_between2);
        }
        if (remark_notBetween1 != null) {
            c.andRemarkNotBetween(remark_notBetween1, remark_notBetween2);
        }
        Integer orderNum_null = TypeCast.getInteger(workSubjectMap.get("orderNum_null"));
        Integer orderNum_notNull = TypeCast.getInteger(workSubjectMap.get("orderNum_notNull"));
        Integer orderNum = TypeCast.getInteger(workSubjectMap.get("orderNum"));
        Integer orderNum_not = TypeCast.getInteger(workSubjectMap.get("orderNum_not"));
        Integer orderNum_greater = TypeCast.getInteger(workSubjectMap.get("orderNum_greater"));
        Integer orderNum_greaterEqual = TypeCast.getInteger(workSubjectMap.get("orderNum_greaterEqual"));
        Integer orderNum_less = TypeCast.getInteger(workSubjectMap.get("orderNum_less"));
        Integer orderNum_lessEqual = TypeCast.getInteger(workSubjectMap.get("orderNum_lessEqual"));
        List<Integer> orderNum_in = TypeCast.getIntegerList(workSubjectMap.get("orderNum_in"));
        List<Integer> orderNum_notIn = TypeCast.getIntegerList(workSubjectMap.get("orderNum_notIn"));
        Integer orderNum_between1 = TypeCast.getInteger(workSubjectMap.get("orderNum_between1"));
        Integer orderNum_between2 = TypeCast.getInteger(workSubjectMap.get("orderNum_between2"));
        Integer orderNum_notBetween1 = TypeCast.getInteger(workSubjectMap.get("orderNum_notBetween1"));
        Integer orderNum_notBetween2 = TypeCast.getInteger(workSubjectMap.get("orderNum_notBetween2"));

        if (orderNum_null != null) {
            c.andOrderNumIsNull();
        }
        if (orderNum_notNull != null) {
            c.andOrderNumIsNotNull();
        }
        if (orderNum != null) {
            c.andOrderNumEqualTo(orderNum);
        }
        if (orderNum_not != null) {
            c.andOrderNumNotEqualTo(orderNum_not);
        }
        if (orderNum_greater != null) {
            c.andOrderNumGreaterThan(orderNum_greater);
        }
        if (orderNum_greaterEqual != null) {
            c.andOrderNumGreaterThanOrEqualTo(orderNum_greaterEqual);
        }
        if (orderNum_less != null) {
            c.andOrderNumLessThan(orderNum_less);
        }
        if (orderNum_lessEqual != null) {
            c.andOrderNumLessThanOrEqualTo(orderNum_lessEqual);
        }
        if (orderNum_in != null) {
            c.andOrderNumIn(orderNum_in);
        }
        if (orderNum_notIn != null) {
            c.andOrderNumNotIn(orderNum_notIn);
        }
        if (orderNum_between1 != null) {
            c.andOrderNumBetween(orderNum_between1, orderNum_between2);
        }
        if (orderNum_notBetween1 != null) {
            c.andOrderNumNotBetween(orderNum_notBetween1, orderNum_notBetween2);
        }
        Date createTime_null = TypeCast.getDate(workSubjectMap.get("createTime_null"));
        Date createTime_notNull = TypeCast.getDate(workSubjectMap.get("createTime_notNull"));
        Date createTime = TypeCast.getDate(workSubjectMap.get("createTime"));
        Date createTime_not = TypeCast.getDate(workSubjectMap.get("createTime_not"));
        Date createTime_greater = TypeCast.getDate(workSubjectMap.get("createTime_greater"));
        Date createTime_greaterEqual = TypeCast.getDate(workSubjectMap.get("createTime_greaterEqual"));
        Date createTime_less = TypeCast.getDate(workSubjectMap.get("createTime_less"));
        Date createTime_lessEqual = TypeCast.getDate(workSubjectMap.get("createTime_lessEqual"));
        List<Date> createTime_in = TypeCast.getDateList(workSubjectMap.get("createTime_in"));
        List<Date> createTime_notIn = TypeCast.getDateList(workSubjectMap.get("createTime_notIn"));
        Date createTime_between1 = TypeCast.getDate(workSubjectMap.get("createTime_between1"));
        Date createTime_between2 = TypeCast.getDate(workSubjectMap.get("createTime_between2"));
        Date createTime_notBetween1 = TypeCast.getDate(workSubjectMap.get("createTime_notBetween1"));
        Date createTime_notBetween2 = TypeCast.getDate(workSubjectMap.get("createTime_notBetween2"));

        if (createTime_null != null) {
            c.andCreateTimeIsNull();
        }
        if (createTime_notNull != null) {
            c.andCreateTimeIsNotNull();
        }
        if (createTime != null) {
            c.andCreateTimeEqualTo(createTime);
        }
        if (createTime_not != null) {
            c.andCreateTimeNotEqualTo(createTime_not);
        }
        if (createTime_greater != null) {
            c.andCreateTimeGreaterThan(createTime_greater);
        }
        if (createTime_greaterEqual != null) {
            c.andCreateTimeGreaterThanOrEqualTo(createTime_greaterEqual);
        }
        if (createTime_less != null) {
            c.andCreateTimeLessThan(createTime_less);
        }
        if (createTime_lessEqual != null) {
            c.andCreateTimeLessThanOrEqualTo(createTime_lessEqual);
        }
        if (createTime_in != null) {
            c.andCreateTimeIn(createTime_in);
        }
        if (createTime_notIn != null) {
            c.andCreateTimeNotIn(createTime_notIn);
        }
        if (createTime_between1 != null) {
            c.andCreateTimeBetween(createTime_between1, createTime_between2);
        }
        if (createTime_notBetween1 != null) {
            c.andCreateTimeNotBetween(createTime_notBetween1, createTime_notBetween2);
        }
        Date updateTime_null = TypeCast.getDate(workSubjectMap.get("updateTime_null"));
        Date updateTime_notNull = TypeCast.getDate(workSubjectMap.get("updateTime_notNull"));
        Date updateTime = TypeCast.getDate(workSubjectMap.get("updateTime"));
        Date updateTime_not = TypeCast.getDate(workSubjectMap.get("updateTime_not"));
        Date updateTime_greater = TypeCast.getDate(workSubjectMap.get("updateTime_greater"));
        Date updateTime_greaterEqual = TypeCast.getDate(workSubjectMap.get("updateTime_greaterEqual"));
        Date updateTime_less = TypeCast.getDate(workSubjectMap.get("updateTime_less"));
        Date updateTime_lessEqual = TypeCast.getDate(workSubjectMap.get("updateTime_lessEqual"));
        List<Date> updateTime_in = TypeCast.getDateList(workSubjectMap.get("updateTime_in"));
        List<Date> updateTime_notIn = TypeCast.getDateList(workSubjectMap.get("updateTime_notIn"));
        Date updateTime_between1 = TypeCast.getDate(workSubjectMap.get("updateTime_between1"));
        Date updateTime_between2 = TypeCast.getDate(workSubjectMap.get("updateTime_between2"));
        Date updateTime_notBetween1 = TypeCast.getDate(workSubjectMap.get("updateTime_notBetween1"));
        Date updateTime_notBetween2 = TypeCast.getDate(workSubjectMap.get("updateTime_notBetween2"));

        if (updateTime_null != null) {
            c.andUpdateTimeIsNull();
        }
        if (updateTime_notNull != null) {
            c.andUpdateTimeIsNotNull();
        }
        if (updateTime != null) {
            c.andUpdateTimeEqualTo(updateTime);
        }
        if (updateTime_not != null) {
            c.andUpdateTimeNotEqualTo(updateTime_not);
        }
        if (updateTime_greater != null) {
            c.andUpdateTimeGreaterThan(updateTime_greater);
        }
        if (updateTime_greaterEqual != null) {
            c.andUpdateTimeGreaterThanOrEqualTo(updateTime_greaterEqual);
        }
        if (updateTime_less != null) {
            c.andUpdateTimeLessThan(updateTime_less);
        }
        if (updateTime_lessEqual != null) {
            c.andUpdateTimeLessThanOrEqualTo(updateTime_lessEqual);
        }
        if (updateTime_in != null) {
            c.andUpdateTimeIn(updateTime_in);
        }
        if (updateTime_notIn != null) {
            c.andUpdateTimeNotIn(updateTime_notIn);
        }
        if (updateTime_between1 != null) {
            c.andUpdateTimeBetween(updateTime_between1, updateTime_between2);
        }
        if (updateTime_notBetween1 != null) {
            c.andUpdateTimeNotBetween(updateTime_notBetween1, updateTime_notBetween2);
        }
        if (workSubjectMap.get("orderBy") != null) {
            workSubjectEx.setOrderByClause((String) workSubjectMap.get("orderBy"));
        }
        if (limitStart != null && limitOffset != null) {
            workSubjectEx.setLimitStart(limitStart);
            workSubjectEx.setLimitOffset(limitOffset);
        }

        return workSubjectEx;
    }
}
